package com.gouwudai.gobbs.service.impl;

import org.extremecomponents.table.limit.Limit;

import com.gouwudai.gobbs.common.Constants;
import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.IUserGradePermissionDAO;
import com.gouwudai.gobbs.pojo.TbbsGradePermission;
import com.gouwudai.gobbs.service.IUserGradePermissionService;
import com.litt.core.exception.DBException;
import com.litt.core.util.ExtremeTableUtil;

public class UserGradePermissionServiceImpl implements IUserGradePermissionService
{
	IUserGradePermissionDAO userGradePermissionDAO;
	
	/**
	 * @param tbbsGradePermission
	 */
	public void save(TbbsGradePermission tbbsGradePermission)
	{	
			userGradePermissionDAO.save(tbbsGradePermission);
	}

	/**
	 * @param Id
	 */
	public void delete(Integer Id)
	{
		userGradePermissionDAO.delete(Id);
	}
	
	/**
	 * @param mgId
	 * @param permissionCode
	 * @param flag
	 */
	public void saveOrUpdate(Integer mgId,Integer permissionCode,Boolean flag)
	{
			userGradePermissionDAO.saveOrUpdate(mgId,permissionCode,flag);
	}

	/**
	 * @param cond
	 * @param pageIndex
	 * @param pageSize
	 * @param sort
	 * @return
	 */
	public IPageList listPage(String[] cond,int pageIndex,int pageSize,String sort)
	{
		return userGradePermissionDAO.listPage(cond,pageIndex, pageSize,sort);
	}
	
	/**
	 * @param request
	 * @throws DBException
	 */
	public void AutoBindingTable(javax.servlet.http.HttpServletRequest request) throws DBException
	{
		String[] cond = new String[4];
		cond[0]=request.getParameter("gradeId");
		cond[1]=request.getParameter("permissionCode");
		cond[2]=request.getParameter("permissionName");
		cond[3]=request.getParameter("queryFlag");
		
		Limit limit = ExtremeTableUtil.getLimit(request, Constants.DEFAULT_PAGE_SIZE);
		IPageList page = this.listPage(cond,limit.getPage(), limit.getCurrentRowsDisplayed(),ExtremeTableUtil.getSort(limit));
		request.setAttribute("resultList",page.getRsList());
		request.setAttribute("totalRows",page.getTotalSize());
	}

	public void setUserGradePermissionDAO(
			IUserGradePermissionDAO userGradePermissionDAO) {
		this.userGradePermissionDAO = userGradePermissionDAO;
	}	
}